package arch.chameleon.module.security.realm.dao;

import java.util.List;

import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.query.Param;

import arch.chameleon.module.security.realm.model.SRole;
import arch.chameleon.module.security.realm.model.SUser;

/**
 * Shiro用户数据访问
 * @author George
 *
 */
public interface ShiroDbDao extends Repository<SUser, String> {
	
	/**
	 * 通过登录名称查询用户信息
	 * @param loginName 登录名称
	 * @return
	 */
	SUser findByLoginName(String loginName);
	
	/**
	 * 通过登录名称查询用户资源权限
	 * @param loginName
	 * @return
	 */
	@Query("select new arch.chameleon.module.security.realm.model.SRole(r.id, r.name) from SUser u, SUserRole ur, SRole r " +
			"where u.id=ur.pk.userId and r.id=ur.pk.roleId and u.loginName=:loginName")
	List<SRole> findRolesByLoginName(@Param("loginName") String loginName);
	
}
